package com.lc202309;

import java.util.HashMap;
import java.util.Map;

/**
 * Description:
 *
 * @Create 2023/9/6 20:53
 * @Version 1.0
 */
public class Solution2404 {
    public int mostFrequentEven(int[] nums) {
        Map<Integer, Integer> map = new HashMap<>();
        int max = 0;
        int res = -1;
        for (int num : nums) {
            if (num % 2 != 0) {
                continue;
            }
            int count = map.getOrDefault(num, 0);
            count += 1;
            map.put(num, count);
            if (count > max) {
                max = count;
                res = num;
                continue;
            }
            if (count < max) {
                continue;
            }
            if (res > num) {
                res = num;
            }
        }
        return res;
    }
}
